<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="/static/css/bootstrap-grid.min.css">
    <!-- <link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> -->
    <link rel="stylesheet" href="../static/font-awesome-4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/css/base.css">
    <link rel="stylesheet" href="/static/css/login.css">

</head>

<body>
    <div class="htmleaf-container">
        <div class="demo form-bg">
            <div class="container">
                <div class="row">
                    <div class="col-md-offset-4 col-md-4 col-sm-offset-3 col-sm-6">
                        <form id="loginForm" class="form-horizontal" action="/login/judge" method="POST" onsubmit="return submitChange()">
                            <div class="heading">Login form</div>
                            <div class="form-group">
                                <i class="fa fa-user"></i><input required name="username" type="text"
                                    class="form-control" placeholder="Username" id="username">
                            </div>
                            <div class="form-group">
                                <i class="fa fa-lock"></i><input required name="password" type="password"
                                    class="form-control" placeholder="Password" id="password" />
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-default"><i class="fa fa-arrow-right"></i></button>
                                <span>Don't have an account? <a href="/register" class="create_account">Sign
                                        up</a></span>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <script src="/static/js/jquery-3.6.0.min.js"></script>
    <script src="/static/js/jquery.form.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
    <script>
    var submitChange = function(){
        $("#loginForm").ajaxSubmit(function (message) {
                var messageJson = JSON.parse(message);
                console.log(messageJson); 
                if (messageJson.code === 400) {
                    alert(messageJson.msg);
                   return false;
                } else if(messageJson.code === 200){
                    window.location.href='/surveyAll'
                }else if(messageJson.code === 202){
                    window.location.href=`/surveypage/${messageJson.id}`;
                }
            });
            return false;
    }
    </script>
</body>

</html>